home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / Idling / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  3.9 KB  |  151 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef FRAME_H
  10. #include "Frame.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"
  15. #endif
  16.  
  17. #ifndef BINDING_K
  18. #include "Binding.k"
  19. #endif
  20.  
  21. // ----- Framework Includes -----
  22. #ifndef FWUTIL_H
  23. #include "FWUtil.h"
  24. #endif
  25.  
  26. #ifndef FWABOUT_H
  27. #include "FWAbout.h"        //::FW_About()
  28. #endif
  29.  
  30. #include "FWPrtIte.h"    // FW_CPartFrameIterator
  31. #include "FWIters.h"    // FW_CFrameFacetIterator
  32. #include "FWIdle.h"        // FW_CIdler
  33. #include "SLMixOS.h"    // FW_GetMainScreenBounds
  34.  
  35. //==============================================================================
  36. #ifdef FW_BUILD_MAC
  37. #pragma segment Idling
  38. #endif
  39.  
  40. FW_DEFINE_AUTO(CIdlingPart)
  41. //==============================================================================
  42. CIdlingPart::CIdlingPart(ODPart* odPart)
  43.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  44.       fIdlingActive(TRUE),
  45.       fIdler(NULL),
  46.       fPresentation(NULL)
  47. {
  48. }
  49.  
  50. //--------------------------------------------------------------------------------
  51. CIdlingPart::~CIdlingPart()
  52. {
  53.     delete fIdler;
  54. }
  55.  
  56. //--------------------------------------------------------------------------------
  57. void 
  58. CIdlingPart::Initialize(Environment* ev)    // Override
  59. {
  60.     FW_CPart::Initialize(ev);
  61.     FW_CSelection* selection = NULL;
  62.     const ODType kMainPresentation = "Apple:Presentation:Idling";
  63.     fPresentation = this->RegisterPresentation(ev, kMainPresentation, TRUE, selection);
  64.     const ODIdleFrequency kIdleFreq = 10;    // ticks
  65.     fIdler = FW_NEW(FW_CIdler, (this, kIdleFreq));
  66.     fIdler->RegisterIdle(ev);
  67. }
  68.  
  69. //--------------------------------------------------------------------------------
  70. FW_CFrame* 
  71. CIdlingPart::NewFrame(Environment* ev, ODFrame* odFrame,
  72.                         FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  73. {
  74.     FW_UNUSED(presentation);
  75.     FW_UNUSED(fromStorage);
  76.     return FW_NEW(CIdlingFrame, (ev, odFrame, presentation, this));
  77. }
  78.  
  79. //--------------------------------------------------------------------------------
  80. FW_CContent* 
  81. CIdlingPart::NewPartContent(Environment* ev)
  82. {
  83.     return NULL;
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. FW_CWindow* 
  88. CIdlingPart::NewDocumentWindow(Environment* ev)
  89. {    
  90.     FW_CRect screenBounds;
  91.     ::FW_GetMainScreenBounds(screenBounds);
  92.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  93.     
  94.     return new FW_CWindow(ev,
  95.                         this,
  96.                          FW_CPart::gViewAsFrameToken,
  97.                         fPresentation,
  98.                         FW_CPoint(FW_IntToFixed(72), FW_IntToFixed(72)),
  99.                         screenBounds.TopLeft(),
  100.                         FW_kDocumentWindow);
  101. }
  102.  
  103. //--------------------------------------------------------------------------------
  104. FW_Boolean 
  105. CIdlingPart::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
  106. {
  107.     FW_UNUSED(theNullEvent);
  108.     FW_CPartFrameIterator iter(ev, this);
  109.     for (CIdlingFrame* frame = (CIdlingFrame*)iter.First(ev);
  110.         iter.IsNotComplete(ev);
  111.         frame = (CIdlingFrame*)iter.Next(ev)) 
  112.         {
  113.             FW_CFrameFacetIterator facetIter(ev, frame);                
  114.             for (ODFacet* facet = facetIter.First(ev);
  115.                 facetIter.IsNotComplete(ev);
  116.                 facet = facetIter.Next(ev)) 
  117.                 {
  118.                     frame->MyToggleColor();
  119.                     frame->Draw(ev, facet, NULL);
  120.                 }    // for facets
  121.         }    // for frames
  122.     return true;
  123. }
  124.  
  125. //--------------------------------------------------------------------------------
  126. void 
  127. CIdlingPart::MyToggleIdling(Environment* ev)
  128. {
  129.     fIdlingActive = ! fIdlingActive;
  130.     fIdler->RegisterIdle(ev, fIdlingActive);
  131. }
  132.  
  133. //--------------------------------------------------------------------------------
  134. FW_Boolean 
  135. CIdlingPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  136. {
  137.     FW_Boolean menuHandled = true;
  138.     switch (theMenuEvent.GetCommandID(ev))
  139.     {
  140.         case kODCommandAbout:
  141.             ::FW_About(ev, this, kAbout);
  142.             break;
  143.  
  144.         default:
  145.             menuHandled = false;
  146.     }
  147.     return menuHandled;
  148. }
  149.  
  150.  
  151.